﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace game
{
    public class Weapon
    {
        public int ProjectileQuantity { get; protected set; }

        protected int shotIntervalMs;
        protected int timeFromShotMs;

        protected float loadLevel = 1.0f;
        protected float loadSpeed = 1.0f;
        protected float shotLoadCost = 1.0f;

        protected Scene scene;
        protected Ship shooter;

        public Weapon(Scene scene, Ship shooter)
        {
            this.scene = scene;
            this.shooter = shooter;
            shotIntervalMs = 1;
            timeFromShotMs = shotIntervalMs;
            ProjectileQuantity = 500;
        }

        public virtual void Update(GameTime gameTime)
        {
            timeFromShotMs += gameTime.ElapsedGameTime.Milliseconds;
            loadLevel += loadSpeed * gameTime.ElapsedGameTime.Milliseconds;
            if (loadLevel > 1.0f)
                loadLevel = 1.0f;
        }

        public virtual bool CanShoot()
        {
            if (timeFromShotMs >= shotIntervalMs && loadLevel >= shotLoadCost && ProjectileQuantity > 0)
            {
                return true;
            }
            return false;
        }

        protected void ShootUpdate()
        {
            timeFromShotMs = 0;
            loadLevel -= shotLoadCost;
            ProjectileQuantity -= 1;
        }

        public virtual bool Shoot(int layerIndex, Vector3 position, Vector3 rotation, Vector3 velocity)
        {
            return true;
        }

        public virtual bool Shoot(int layerIndex, Vector3 position, Vector3 rotation)
        {
            return true;
        }
    }
}
